#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QUdpSocket>
#include "tcpserver.h"

QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE

// 标记消息类型：消息，新用户加入，用户退出，文件名，拒绝接收文件
enum MessageType {
    Message,
    NewParticipant,
    ParticipantLeft,
    Filename,
    Refuse
};

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();

protected:
    void newParticipant(QString username, QString localHostName, QString idAddress);
    void participantLeft(QString username, QString localHostName,QString time);
    void sendMessage(MessageType type, QString serverAddress=""); // 发送数据
    QString getIP(); // 获取系统IP地址
    QString getUsername(); // 获取系统用户名
    QString getMessage();
    void hasPendingFile(QString userName, QString serverAddress, QString clientAddress, QString fileName);

private:
    Ui::Widget *ui;
    QUdpSocket *udpSocket;
    qint16 port;
    QString fileName;
    TcpServer *server;

private slots:
    void getFileName(QString);
    void processPendingDatagrams();
    void on_sendButton_clicked();
    void on_sendToolBtn_clicked();
};
#endif // WIDGET_H
